//https://leetcode.cn/problems/target-sum/

class Solution {
    int ret;
    public int findTargetSumWays(int[] nums, int target) {
        dfs(nums, target, 0, 0);
        return ret;
    }
    public void dfs(int[] nums, int target,int pos, int pathOfSum) {
        if(pos == nums.length) {
            if(pathOfSum == target) ret++;
            return;
        }
        //加 //参数形式->函数自动回溯
        dfs(nums, target, pos + 1, pathOfSum + nums[pos]);

        //减 //参数形式->函数自动回溯
        dfs(nums, target, pos + 1, pathOfSum - nums[pos]);
    }
}